define([
    "commonLet",
    "ngController",
    "ngDiSlider", "ngDiSliderContent",
    "ngDiBottom", "ngDiBottomContent",
    "ngDiCanvas",
    "ngDiDrag", "ngDiDragProperty", "ngDiDragStructure", "ngDiDragEyesmark", "ngDiDragSearch", "ngDiDragSign",
    "ngDiDragSection", "ngDiDragLocation", "ngDiDragResolve", "ngDiDragSetting", "ngDiModelLayer",
    "jquery",
], function(commonLet) {
    // "ngModule",
    // new
    let pageInit = function() {
        console.log("pageInit：页面样式初始化");
    };

    Object.assign(pageInit.prototype, {
        // baseLet
        // baseUrl
        baseUrl: commonLet.BASEURL,
        // 引用angular内部方法，抛出去给API使用
        angularScope: function () {
            // console.log("pageInit***angularScope***function");
        },
        // 初始化
        init: function(event) {
            if (!event) return;

            // 加缀时间戳
            this.time = commonLet.TIME;
            let ngApp = "bimApiAgular" + this.time;
            let ngController = "bimApiCtrl" + this.time;

            // 整体外壳
            let BIMViewAPIcontent = $("<div class='BIMView-API-content'></div>");
            BIMViewAPIcontent.attr({"onselectstart": "return false", "ng-app": ngApp, "ng-controller": ngController});
            $("#" + event).append(BIMViewAPIcontent);
            $("#" + event).append("<link rel='stylesheet' type='text/css' href='" +
                this.baseUrl +
                "/Module/css/bimView-api-4.css?" +
                this.time + "' />");

            BIMViewAPIcontent.append("<div bimview-api-slider></div>");
            BIMViewAPIcontent.append("<div bimview-api-bottom></div>");
            BIMViewAPIcontent.append("<div bimview-api-drag></div>");
            BIMViewAPIcontent.append("<div bimview-api-canvas3d></div>");
            $(".BIMView-API-content").css("display", "none");

            // 手动启动angular
            angular.bootstrap(document.querySelector(".BIMView-API-content"), [ngApp]);
            this.changeCss();

            // 通过controller来获取Angular应用
            let appElement = document.querySelector("[ng-controller="+ngController+"]");
            // 获取$scope变量
            let $scope = angular.element(appElement).scope();
            // 调用angular中变量/方法
            // console.log($scope.demo);
            // $scope.modelDemo();
            // 如果改变了angular中的值，想同步到Angular控制器中，则需要调用$apply()方法即可
            // $scope.$apply();

            // 给抛出去的方法赋值
            Object.assign(this.angularScope.prototype,{
                scope: $scope,
                initCanvas: function (id, callback) {
                    setTimeout(function () {
                        $(".BIMView-API-content").css("display", "block");
                        callback(id);
                    });
                },
            });
        },

        changeCss: function () {
            // 一些小组件的方法事件（不方便用css表示或者不适合其他）
            // 下拉组件dropdown系列相关
            $(".BIMView-API-content .BIMView-API-drag .dropdown .dropbtn").on("click", function() {
                $(this).parent(".dropdown").find(".dropdown-content").css("display", "block");
            });
            $(".BIMView-API-content .BIMView-API-drag .dropdown, .BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").on("mouseleave", function() {
                $(this).find(".dropdown-content").css("display", "none");
                $(this).parent(".dropdown").find(".dropdown-content").css("display", "none");
            });
            $(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content a").on("click", function() {
                $(this).parent(".dropdown-content").css("display", "none");
            });
        }
    });

    return pageInit;
});